package org.lds.scheduled.job.worker.listener;

import org.lds.scheduled.job.common.model.AddJobModel;
import org.lds.scheduled.job.common.model.RemoveJobModel;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Component
public class JobListeners {
    private final List<JobListener> listeners = new ArrayList<>();

    public JobListeners(Map<String, JobListener> jobListenerMap) {
        for (JobListener jobListener : jobListenerMap.values()) {
            listeners.add(jobListener);
        }
    }

    public void publishAddJob(AddJobModel addJobModel) {
        for (JobListener listener : listeners) {
            listener.onJobAdded(addJobModel);
        }
    }

    public void publishRemoveJob(RemoveJobModel removeJobModel) {
        for (JobListener listener : listeners) {
            listener.onJobRemoved(removeJobModel);
        }
    }
}
